package com.jpa.manytomany;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * <p>Title:Student</p>
 * <p>Description:</p>
 * @company sinobest 
 * @author Administrator
 * @date 2016年10月20日 上午12:49:43
 * 
 */
@Entity
@Table(name="t_student")
public class Student {
	@Id
	@GeneratedValue
	private Integer id;
	private String name;
	
	@ManyToMany(cascade ={CascadeType.REFRESH})
	@JoinTable(name="t_student_teacher",
		inverseJoinColumns= @JoinColumn(name="teacher_id"),//外键表
		joinColumns={@JoinColumn(name="student_id")}) //中间关系表
	private Set<Teacher>  teachers = new HashSet<Teacher>();

	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Teacher> getTeachers() {
		return teachers;
	}

	public void setTeachers(Set<Teacher> teachers) {
		this.teachers = teachers;
	}
	
}
